#include "Story.h"

Story::Story(void)
:m_scene(NULL),
m_dialog(NULL)
{
}

Story::~Story(void)
{
}

int Story::GetID()
{
	TiXmlAttribute* xa=m_dialog->FirstAttribute();
	while(xa!=NULL&&strcmp(xa->Name(),"ID"))
	{
		xa=xa->Next();
	}
	if(xa!=NULL)
	{
		return atoi(xa->Value());
	}
	else
	{
		return -1;
	}
}

int Story::GetStation()
{
	TiXmlAttribute* xa=m_dialog->FirstAttribute();
	while(xa!=NULL&&strcmp(xa->Name(),"Station"))
	{
		xa=xa->Next();
	}
	if(xa!=NULL)
	{
		return atoi(xa->Value());
	}
	else
	{
		return -1;
	}
}

int Story::GetBackground()
{
	TiXmlAttribute* xa=m_scene->FirstAttribute();
	while(xa!=NULL&&strcmp(xa->Name(),"Background"))
	{
		xa=xa->Next();
	}
	if(xa!=NULL)
	{
		return atoi(xa->Value());
	}
	else
	{
		return -1;
	}
}

int Story::GetState()
{
	TiXmlAttribute* xa=m_dialog->FirstAttribute();
	while(xa!=NULL&&strcmp(xa->Name(),"State"))
	{
		xa=xa->Next();
	}
	if(xa!=NULL)
	{
		return atoi(xa->Value());
	}
	else
	{
		return -1;
	}
}

const char* Story::GetDialog()
{
	return m_dialog->GetText();
}

BOOL Story::NextDialog()
{
	if(m_dialog->NextSiblingElement()!=NULL)
	{
		m_dialog=m_dialog->NextSiblingElement();
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

BOOL Story::NextScene()
{
	if(m_scene->NextSiblingElement()!=NULL)
	{
		m_scene=m_scene->NextSiblingElement();
		m_dialog=m_scene->FirstChildElement();
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

int Story::PersonLeave()
{
	TiXmlAttribute* xa=m_dialog->FirstAttribute();
	while(xa!=NULL&&strcmp(xa->Name(),"Leave"))
	{
		xa=xa->Next();
	}
	if(xa!=NULL)
	{
		return atoi(xa->Value());
	}
	return -1;
}

BOOL Story::Fight()
{
	if(strcmp(m_dialog->Value(),"Fight")==0)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}